package com.java.demo;

import java.util.Random;
import java.util.Scanner;


public class Lucky {
    public  static  String  name;
    public static String  mima;
    public static boolean loginflag = false;

    public static int memberID;


    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String s;
        do {
            System.out.println("**********欢迎进入奖励富翁系统*********");
            System.out.println("1.注册");
            System.out.println("2.登录");
            System.out.println("3.抽奖");




            System.out.println("*****************");
            System.out.println("请选择菜单信息");
            int  choice = scanner.nextInt();
            switch (choice){
                case 1:
                    System.out.println("用户选择了注册");
                    regist(scanner);
                    break;
                case 2:
                    System.out.println("用户选择了登录");
                    loginflag = login(scanner);
                    break;
                case 3:
                    System.out.println("用户选择了抽奖");
                    lucky(loginflag,scanner);
                    break;
                default:
                    System.out.println("我真的没钱了，我需要快点找到工作了");
            }
            System.out.println("是否继续？Y/N");
            s = scanner.next();
        } while ("y".equals(s));
        System.out.println("游戏结束，欢迎下次再来，我日你吗的，爱玩不爱，狗东西");
    }

    private static void lucky(boolean loginflag,Scanner scanner) {
        if(!loginflag){
            System.out.println("请先去登录，不登录这个点没法使用");
            return;
        }
        System.out.println("请输入你的会员Id");
          int  memberID =  scanner.nextInt();
        int i = 1;
        do {
            System.out.println("请输入1确定开始抽奖");
            if("1".equals(scanner.next())){

                Random random = new Random();
                int luchyID = random.nextInt(10000-1000)+1000;
                System.out.println("第"+ i +"个幸运数字是"+ luchyID);

                if(luchyID == memberID){
                    System.out.println("你真的是太幸运了，你真的很牛，中了大奖了，兄弟！");
                }else {
                    System.out.println("很遗憾你没有中奖啊");
                }


            }
            i++;

        } while (i <= 3 );
    }


    //登录功能
    private static boolean login(Scanner scanner) {
        //注册之前请先登录
        if(name == null){
            System.out.println("请先去注册，等注册完了再说登录的事情");
            return false;
        }
        int count = 5;
        do {
            count --;
            System.out.println("请输入你的账号");
            String loginname = scanner.next();
            System.out.println("请输入你的密码");
            String loginmima = scanner.next();
            if(loginname.equals(name) && loginmima.equals(mima)){
                System.out.println("登录成功");
                return true;
            }else {
                System.out.println("登录失败，请检查用户名或者密码");
                System.out.println("还剩下"+count + "次机会");
            }
            if (count == 0){
                System.out.println("你的次数已经用完，💩，返回主页面！");
                return false;

            }

        } while (true);


    }

    //注册功能
    private static void regist(Scanner scanner) {

        //注册流程
        //输入个人注册信息
        System.out.println("请输入您的用户名");
//        因为上边有scanner，就不用再次创建了，直接把值传进来。
         name = scanner.next();
        System.out.println(name);
        System.out.println("请输入您的密码");
         mima = scanner.next();
        System.out.println(mima);

        Random random = new Random();
        int memberID = random.nextInt(10000-1000)+1000;
        System.out.println("恭喜你，你的会员账号是" + memberID);
        System.out.println("注册成功，信息如下：");

        System.out.println("名字是"+name + "\n" +"密码是"+ mima + "\n" + memberID);


    }
}
